﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL
{
    public  class FolderDAL:DALBase
    {
        private static ObjectQuery<FileDirPath> GetFilePath()
        {
            return DataEntites.FileDirPath;
        }


        /// <summary>
        /// Get FilePath List
        /// </summary>
        /// <returns></returns>
        public static List<FileDirPath> GetFolderList()
        {
            List<FileDirPath> list = new List<FileDirPath>();
            foreach (var item in GetFilePath())
            {
                list.Add(item); 
            }
            return list;
        }

        /// <summary>
        /// Get FilePath object
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static FileDirPath GetFolderObj(int id)
        {
            return DataEntites.FileDirPath.First(f => f.id == id);
        }

        public static FileDirPath GetFolderObj(string name)
        {
            return DataEntites.FileDirPath.First(f=>f.FileDir.Contains(name));
        }
        /// <summary>
        /// add Folder
        /// </summary>
        /// <param name="obj"></param>
        public static void AddFolder(FileDirPath obj)
        {
            DataEntites.AddToFileDirPath(obj);
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Update Folder
        /// </summary>
        /// <param name="obj"></param>
        public static void UpdateFolder(FileDirPath obj)
        {
            FileDirPath filePath = GetFolderObj(obj.id);
            filePath.FileDir = obj.FileDir;
            filePath.Des = obj.Des;
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Delete Folder
        /// </summary>
        /// <param name="obj"></param>
        public static void DeleteFolder(FileDirPath obj)
        {
            FileDirPath filePath = GetFolderObj(obj.id);
            DataEntites.DeleteObject(filePath);
            DataEntites.SaveChanges();
        }
    }
}
